//
//  jobViewController.m
//  7ZhiLe
//
//  Created by 海明洋 on 15/3/13.
//  Copyright (c) 2015年 海明洋. All rights reserved.
//

#import "jobViewController.h"

@interface jobViewController ()
@property (nonatomic,strong) NSMutableArray *btnArr;
@property (nonatomic,strong) UITableView *tableView1;
@property (nonatomic,strong) UITableView *tableView2;
@property (nonatomic,strong) UIScrollView *scrollView;
@property (nonatomic,strong) UIView *selectedView;
@property (nonatomic,assign) float btn1X;
@property (nonatomic,assign) float btn2X;
@property (nonatomic,assign) float selectedViewX;
@property (nonatomic,assign) float selectedViewY;
@end

@implementation jobViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor=[UIColor whiteColor];
    
    _btnArr=[[NSMutableArray alloc] init];
    _selectedView=[[UIView alloc] init];
    _selectedView.backgroundColor=[UIColor blueColor];
    _selectedView.alpha=0.5;
    
#pragma mark - 选项按钮
    for (int i=0; i<2; i++) {
        UIButton *button=[[UIButton alloc] init];
        
        button.frame=CGRectMake([self screenSize].width/2-(120+20)/2+(60+20)*i, 80, 60, 60);
        
        switch (i) {
            case 0:{
                _selectedView.frame=button.frame;
                _btn1X=button.center.x;
                [button setBackgroundImage:[UIImage imageNamed:@"Q1.png"] forState:UIControlStateNormal];
                [button addTarget:self action:@selector(btnAct1:) forControlEvents:UIControlEventTouchUpInside];
            }
                break;
            case 1:{
                _btn2X=button.center.x;
                [button setBackgroundImage:[UIImage imageNamed:@"Q2.png"] forState:UIControlStateNormal];
                [button addTarget:self action:@selector(btnAct2:) forControlEvents:UIControlEventTouchUpInside];
            }
                break;
            default:
                break;
        }
        
        button.tag=100+i;
        [_btnArr addObject:button];
        [self.view addSubview:button];
    }
    
    _selectedViewX=_selectedView.center.x;
    _selectedViewY=_selectedView.center.y;
    [self.view addSubview:_selectedView];
    
    //分割线
    UIView *line=[[UIView alloc] initWithFrame:CGRectMake(0, 80+80-1, [self screenSize].width, 0.5)];
    line.backgroundColor=[UIColor grayColor];
    line.alpha=0.6;
    [self.view addSubview:line];
    
#pragma mark - 滚动列表
    _scrollView=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 80+80, [self screenSize].width, self.view.frame.size.height-80-80)];
    _scrollView.delegate=self;
    _scrollView.pagingEnabled=YES;
    _scrollView.contentSize=CGSizeMake([self screenSize].width*2, self.view.frame.size.height-80-80);
    _scrollView.showsHorizontalScrollIndicator=NO;
    
    _tableView1=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, _scrollView.frame.size.width, _scrollView.frame.size.height) style:UITableViewStylePlain];
    _tableView1.delegate=self;
    _tableView1.dataSource=self;
    _tableView1.backgroundColor=[UIColor lightGrayColor];
    _tableView1.showsVerticalScrollIndicator=NO;
    
    _tableView2=[[UITableView alloc] initWithFrame:CGRectMake([self screenSize].width, 0, _scrollView.frame.size.width, _scrollView.frame.size.height) style:UITableViewStylePlain];
    _tableView2.delegate=self;
    _tableView2.dataSource=self;
    _tableView2.backgroundColor=[UIColor lightGrayColor];
    _tableView2.showsVerticalScrollIndicator=NO;
    
    
    [_scrollView addSubview:_tableView1];
    [_scrollView addSubview:_tableView2];
    [self.view addSubview:_scrollView];
}

#pragma mark - 选项按钮方法
- (void)btnAct1:(UIButton *)btn
{
    [_scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
}

- (void)btnAct2:(UIButton *)btn
{
    [_scrollView setContentOffset:CGPointMake([self screenSize].width, 0) animated:YES];
}

#pragma mark - UIScrollView Delegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    float offx=scrollView.contentOffset.x;
    
    float offMovePercent=offx/[self screenSize].width;
    float frameCenterMove=offMovePercent*(_btn2X-_btn1X);
    //NSLog(@"frameMove=%f",frameCenterMove);
    _selectedView.center=CGPointMake(_selectedViewX+frameCenterMove, _selectedViewY);
    
}

#pragma mark - UITableView Delegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44*1.75;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    //    model *mod=[model shareModel];
    //    return mod.collectionDataArr.count;
    return 20;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cellStr=@"cell";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellStr];
    if (cell==nil) {
        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellStr];
    }
    
    if (tableView==_tableView1) {
        cell.textLabel.text=@"1";
    } else
        cell.textLabel.text=@"2";
    
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    
    return cell;
}

//获取ios屏幕大小（去掉状态条）
- (CGSize) screenSize
{
    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
    CGSize size = [UIScreen mainScreen].bounds.size;
    UIApplication *application = [UIApplication sharedApplication];
    if (UIInterfaceOrientationIsLandscape(orientation))
    {
        size = CGSizeMake(size.height, size.width);
    }
    if (application.statusBarHidden == NO)
    {
        size.height -= MIN(application.statusBarFrame.size.width, application.statusBarFrame.size.height);
    }
    return size;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
